package com.felix.sample;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;
import java.util.TimeZone;

/**
 * Created by Felix.Zhong on 2018/6/29 16:38
 * 日期工具类
 */
public class DateUtils {

    private static final String FORMAT1 = "yyyy/MM/dd";
    private static final String FORMAT2 = "yyyy/MM/dd HH:mm";
    private static final String FORMAT3 = "yyyy-MM-dd HH:mm:ss";
    private static final String FORMAT4 = "yyyy-MM-dd HH:mm";
    private static final String FORMAT5 = "yyyy/MM/dd HH:mm";
    private static final String FORMAT6 = "MM/dd HH:mm";
    private static final String FORMAT7 = "yyyy_MM_dd_HH_mm_ss";
    private static final String FORMAT8 = "HH:mm:ss";
    private static final String FORMAT_GOOGLE_VERIFICATION = "yyyy/MM/dd  HH:mm:ss";

    public static String format1(long time) {
        return format(time, FORMAT1);
    }

    public static String format2(long time) {
        return format(time, FORMAT2);
    }

    public static String format3(long time) {
        return format(time, FORMAT3);
    }

    public static String format4(long time) {
        return format(time, FORMAT4);
    }

    public static String format5(long time) {
        return format(time, FORMAT5);
    }

    public static String format6(long time) {
        return format(time, FORMAT6);
    }

    public static String format7(long time) {
        return format(time, FORMAT7);
    }

    public static String format8(long time) {
        return format(time, FORMAT8);
    }

    public static String format(long time, String pattern) {
        SimpleDateFormat format = new SimpleDateFormat(pattern, Locale.getDefault());
        return format.format(new Date(time));
    }

    public static String format(Date date, String pattern) {
        SimpleDateFormat format = new SimpleDateFormat(pattern, Locale.getDefault());
        return format.format(date);
    }

    public static String formatGoogleVerification(long time) {
        SimpleDateFormat format = new SimpleDateFormat(FORMAT_GOOGLE_VERIFICATION, Locale.getDefault());
        return format.format(new Date(time));
    }

    /**
     * 获取带时区的日期 https://blog.csdn.net/landebug/article/details/9997103
     *
     * @return 格式为 2018/09/03 16:15:33(GMT+08:00)
     */
    public static String getDateWithTimeZone() {
        TimeZone tz = TimeZone.getDefault();
        String s = tz.getDisplayName(false, TimeZone.SHORT);
        return formatGoogleVerification(System.currentTimeMillis()) + "(" + s + ")";
    }
}
